<?php
if ($_SESSION['niveauAuth']=='1'or $_SESSION['niveauAuth']=='2'or $_SESSION['niveauAuth']=='3' or $_SESSION['niveauAuth']=='4' or $_SESSION['niveauAuth']=='5'or $_SESSION['niveauAuth']=='6'or $_SESSION['niveauAuth']=='7' or $_SESSION['niveauAuth']=='8'){

/**
 * Controleur permettant de lister l'ensemble des clients
 */
require_once('dao/ClientDao.php');

// Initialisation des variables
$searchId = "";

// Id du client à afficher
if(isset($_GET['id'])){
	$clients = ClientDao::searchById($_GET['id']);
	
		if (count($clients) == 0){
		$error="Aucun client trouvé";
		
	}
}
//mise a jour login password
if (isset($_POST['action'])){
	if ($_POST['action'] == "update1"){
		
$code_client_hto =$_GET['id'];
$login = $_POST['login'];
$password = $_POST['password'];



$updateOK = ClientDao::update1($code_client_hto,$login,$password);
		
		if ($updateOK){
			$message="Mise à du client réalisée";
			header('location: liste-client');
			
			
		} else {
			$error = "Mise à jour impossible";
		}

	}
}


// Rendu de la page
echo $twig->render('majloginpassword.html', 
		array(	'client' => $clients[0],
				'searchId' => $searchId, 
				'message' => $message, 
				'error' => $error));

}
else {
	redirect("home-admin");
}


